package ahblue.cn.tanzi.model.collect;

import android.content.Context;
import android.widget.Toast;

import com.google.gson.annotations.SerializedName;

import java.util.List;

import ahblue.cn.tanzi.data.source.ApiCallback;
import ahblue.cn.tanzi.data.source.RemoteRepository;

/**
 * Created by fengdongfei on 2018/12/1.
 */

public class CollectModel {


    /**
     * id : 13
     * title : 测试
     * image : 20181126%5Caec95ea0882fa3aba9d8c352cf1caf1f.jpg
     * file : 20181126%5Caa5dee383a5ce4115eaa6f01d0a6a913.mp4
     * member_name : 我好安排
     * add_time : 1543242919
     * see_count : 0
     * early_time : 406574
     * type : 2
     * comment_count : 0
     */

    public String id;
    public String title;
    public String image;
    public String file;
    public String member_name;
    public String add_time;
    public String see_count;
    public String member_avatar;
    public int early_time;
    public int type;
    public int comment_count;


    public static void igetCollect(final Context context ,
                                   String token,
                                   final CollectListener loginListener) {
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.getCollect(token, new ApiCallback<List<CollectModel>>() {
            @Override
            public void onSuccess(List<CollectModel> data) {
                if (null != loginListener) {
                    loginListener.conver(data);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context, errorMsg, Toast.LENGTH_LONG).show();
                if (null != loginListener) {
                    loginListener.conver(null);
                }
            }
        });
    }

    public static void delCollect(final Context context ,
                                   String token,
                                   String id,
                                   String object_type,
                                   final DelCollectListener loginListener) {
        RemoteRepository repo = RemoteRepository.getsInstance();
        repo.delCollect(token, id,object_type,new ApiCallback<CollectModel>() {
            @Override
            public void onSuccess(CollectModel data) {
                if (null != loginListener) {
                    loginListener.conver(data);
                }
            }

            @Override
            public void onFailed(String errorMsg) {
                Toast.makeText(context, errorMsg, Toast.LENGTH_LONG).show();
                if (null != loginListener) {
                    loginListener.conver(null);
                }
            }
        });
    }

    public interface CollectListener{
        void conver(List<CollectModel> model);
    }

    public interface DelCollectListener{
        void conver(CollectModel model);
    }

    @Override
    public String toString() {
        return "CollectModel{" +
                "id='" + id + '\'' +
                ", title='" + title + '\'' +
                ", image='" + image + '\'' +
                ", file='" + file + '\'' +
                ", member_name='" + member_name + '\'' +
                ", add_time='" + add_time + '\'' +
                ", see_count='" + see_count + '\'' +
                ", member_avatar='" + member_avatar + '\'' +
                ", early_time=" + early_time +
                ", type=" + type +
                ", comment_count=" + comment_count +
                '}';
    }
}
